<include file="Common:minheader" />
<!-- /. NAV SIDE  -->
<form class="layui-form" action="">
    <input type="hidden" name="user_id" value="{$userInfo.id}">
	<div class="layui-form-item">
		<label class="layui-form-label">所属用户</label>
		<div class="layui-input-block">
		  <input value="{$userInfo.username}({$userInfo.mobile})" type="text" name="" required  lay-verify="required" placeholder="请输入所属用户" autocomplete="off" class="layui-input" disabled="true">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">所属场馆</label>
		<div class="layui-input-block">
			<select name="store_id">
				<option value="">请选择</option>
				<notempty name="storeList">
					<volist name="storeList" id="vo" key="key">
						<option value="{$vo.id}" <if condition="$key==1">selected</if>>{$vo.title}</option>
					</volist>
				</notempty>
			</select>
		</div>
	</div>
	<div class="layui-form-item" >
		<label class="layui-form-label">所属卡</label>
		<div class="layui-input-block">
			<select name="goods_id" lay-search lay-filter="auitSelect">
				<option value="">请选择</option>
				<notempty name="goodsList">
					<volist name="goodsList" id="vo" key="key">
						<option value="{$vo.id}">{$vo.goods_title}</option>
					</volist>
				</notempty>
			</select>
		</div>
	</div>
	<div class="layui-form-item" style="display:none" id="cardNums">
		<label class="layui-form-label">卡次数</label>
		<div class="layui-input-block">
		  <input id="card_nums" type="text" name="nums" required  lay-verify="required" placeholder="请输入卡次数" autocomplete="off" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item" style="display:none" id="validTime">
		<label class="layui-form-label">有效期</label>
		<div class="layui-input-inline">
		    <input id="valid_time" type="text" name="valid_time" required  lay-verify="required" placeholder="请输入有效期" autocomplete="off" class="layui-input">
		</div>
		<div class="layui-form-mid layui-word-aux">天</div>
	</div>
	<div class="layui-form-item layui-form-text">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
          <textarea name="memo" placeholder="请输入内容" class="layui-textarea">{$info.memo}</textarea>
        </div>
    </div>
	<div class="layui-form-item">
		<label class="layui-form-label">序号</label>
		<div class="layui-input-inline">
		  <input value="0" type="text" name="sort" placeholder="请输入序号" autocomplete="off" class="layui-input">
		</div>
		<div class="layui-form-mid layui-word-aux">数字越大排序越靠前</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">是否启用</label>
		<div class="layui-input-block">
		  <input type="radio" name="status" value="1" title="是" checked>
		  <input type="radio" name="status" value="0" title="否">
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
		  <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
		  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</div>
  </div>
</form>
<script>
	//Demo
	layui.use('form', function(){
        var form = layui.form;
        //监听提交
        form.on('select(auitSelect)',function(data){ //
        	var goods_id = data.value;
        	$('#cardNums').hide();
        	$('#validTime').hide();
        	if(goods_id){
        	    $.ajax({
            		url:"{:U('Common/getGoodsInfo')}",
            		type:'post',
            		dataType:'json',
            		data:{'goods_id':goods_id},
            		success:function(data){
            		    console.log(data);
            			if(data.code==1){
            			    $('#card_nums').val(data.data.total_nums);
            			    $('#valid_time').val(data.data.valid_time);
            				$('#cardNums').show();
        		            $('#validTime').show();
            			}else{
            			    layer.alert(data.message);
            			}
            		}
            	});
        	}
        });
        form.on('submit(formDemo)', function(data){
        	var cont = data.field;
        	$.ajax({
        		url:"{:U('Users/addUserCard')}",
        		type:'post',
        		dataType:'json',
        		data:cont,
        		success:function(data){
        			if(data.code==0){
        				layer.alert(data.message);
        			}else{
        				layer.alert(data.message, function(index){
        					//do something
        					window.parent.location.reload();
        					var index = parent.layer.getFrameIndex(window.name); 
        					parent.layer.close(index);
        				});
        			}
        		}
        	});
        	//layer.msg(JSON.stringify(data.field));
        	return false;
        });
	});
</script>
<!-- /. PAGE INNER  -->
<include file="Common:footer" />